<!-- src/views/message/LikeMessage.vue -->
<template>
  <div class="like-messages">
    <pre>{{ messages }}</pre>
    <div
        v-for="like in messages"
        :key="like.likeId"
        class="like-item"
        :class="{ unread: !like.isRead }"
    >
      <div class="like-header">
        <img :src="like.likerAvatar" :alt="like.likerName" class="avatar">
        <div class="like-info">
          <div class="like-name">{{ like.likerName }}</div>
          <div class="like-time">{{ formatDate(like.likeTime) }}</div>
        </div>
        <div v-if="!like.isRead" class="unread-indicator"></div>
      </div>
      <div class="like-content">
        <p>点赞了你的帖子《{{ like.contentTitle }}》</p>
        <div class="post-preview">
          <img :src="like.contentImage" :alt="like.contentTitle" class="post-image">
          <div class="post-title">{{ like.contentTitle }}</div>
          <div class="like-count">
            <i class="fa fa-heart text-red-500"></i>
            <span>{{ like.likeCount }}</span>
          </div>
        </div>
      </div>
      <div class="message-actions">
        <button @click.stop="markRead(like.likeId)" v-if="!like.isRead">标记已读</button>
        <button @click.stop="deleteMessage(like.likeId)">删除</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    messages: {
      type: Array,
      required: true
    }
  },
  methods: {
    markRead(likeId) {
      this.$emit('mark-read', likeId);
    },
    deleteMessage(likeId) {
      this.$emit('delete-message', likeId);
    },
    formatDate(date) {
      if (!date) return '';
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      return `${hours}:${minutes}`;
    }
  }
};
</script>

<style scoped>
.like-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.like-item {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
}

.like-item.unread {
  border-left: 4px solid #F97316;
}

.like-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 12px;
}

.like-info {
  flex: 1;
}

.like-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.like-time {
  color: #999;
  font-size: 12px;
}

.unread-indicator {
  width: 6px;
  height: 6px;
  background: #F97316;
  border-radius: 50%;
  margin-left: 8px;
}

.like-content {
  margin: 8px 0;
}

.post-preview {
  display: flex;
  align-items: center;
  background: #f5f7fa;
  border-radius: 4px;
  padding: 12px;
  margin-top: 8px;
}

.post-image {
  width: 60px;
  height: 60px;
  border-radius: 4px;
  margin-right: 12px;
}

.post-title {
  flex: 1;
  font-size: 14px;
  color: #333;
}

.like-count {
  display: flex;
  align-items: center;
  color: #165DFF;
  font-size: 12px;
  margin-left: auto;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.message-actions button {
  background: none;
  border: none;
  color: #165DFF;
  font-size: 12px;
  cursor: pointer;
}
.message-actions button:hover {
  text-decoration: underline;
}
</style>
